<%@page import="com.hhit.collaborative_learning.utils.Utils"%>
<%@page import="com.hhit.collaborative_learning.dao.impl.PublicDaoImplMySql"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
PublicDaoImplMySql dao=new PublicDaoImplMySql();
HashMap<String ,Object> map=dao.getAttention(Integer.parseInt(Utils.getCookieValue("userId", request)));
int myAttention=Integer.parseInt(map.get("myAttention")+"");
int attentionEachOther=Integer.parseInt(map.get("attentionEachOther")+"");
int attentionMe=Integer.parseInt(map.get("attentionMe")+"");
session.setAttribute("blog_myAttention", myAttention);
session.setAttribute("blog_attentionEachOther", attentionEachOther);
session.setAttribute("blog_attentionMe", attentionMe);
int currentPage=Integer.parseInt(map.get("currentPage")+"");
request.setAttribute("list", map.get("list"));
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
	<link type="text/css" rel="Stylesheet" href="<%=basePath%>css/main.css" />
	<link rel="stylesheet" href="<%=basePath%>css/index.css">
	<link rel="stylesheet" href="<%=basePath%>css/common1.css">
	<link rel="stylesheet" href="<%=basePath%>css/persion_space_A.css">
	<link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css">
	<script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/jquery.cookie.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/csdn.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/master.js"></script>

  </head>
  
  <body style="zoom:1">
  <input id="attention" type="hidden" value="<%=map.get("attentionUsers")%>"/>
  <input id="type" type="hidden" value="0"/>
  <div id="wrap">

		<div class="head">
		<div style="float:right; margin-top:20px; color:Red;"></div>
  </div>
  <div class="tabs_header">
			<ul id="ul_tab" class="tabs">
				<li><a href="bloglist.jsp"><span>文章管理</span></a></li>
				<li><a href="<%=basePath %>learning/manage_comment.jsp"><span>评论管理</span></a></li>
				<li><a href="<%=basePath %>learning/postedit.jsp"><span>发表文章</span></a></li>
				<li><a href="<%=basePath %>learning/draft.jsp"><span>草稿箱</span></a></li>
				<li><a href="<%=basePath %>learning/deleted.jsp"><span>回收站</span></a></li>
				<li><a href="<%=basePath %>learning/myattention.jsp"><span>我的关系</span></a></li>
				<c:if test="${cookie.cl_blogRight.value ne null}">
				<li><a href="<%=basePath %>learning/myright.jsp"><span>我的权限</span></a></li>
				</c:if>
			</ul>
		</div>
		<script type="text/javascript">
			setTab();
			
			function change_tab(e,type){
				if($(e).attr("class")=="current_foucus"&&$("ul#myConnect li:first").attr("flag")!="flag"){
					return;
				}
				if((type=="0"&&<%=myAttention%>==0)||(type=="1"&&<%=attentionMe%>==0)||(type=="2"&&<%=attentionEachOther%>==0)){
					$("ul#myConnect li").remove();
					$("#c_more").remove();
					var msg="<li flag='flag' class='icon-th-list no-mess' style='margin-bottom: 0; height: auto;'><span>暂时还没有关注关系</span></li>";
					$("#myConnect").append(msg);
					return;
				}
				$.post("<%=basePath%>GetAttentionServlet",{attention:$("#attention").val(),type:type,userId:$.cookie("userId")},function(data,status){
					var json=eval("("+data+")");
					var currentPage=json.currentPage;
					var list=json.list;
					$("ul#myConnect li").remove();
					for(var i=0;i<list.length;i++){
						var msg=""; 
						if(type=="1"){
							msg+="<li style='height:82px;'><dl><dt><a href='<%=basePath%>learning/personal.jsp?userId="+list[i].userId+"' target='_blank'><img src='<%=basePath %>userIcons/"+list[i].userIcon+"' username='"+list[i].userId+"'></a></dt><dd class='connection_name'><a href='<%=basePath%>learning/personal.jsp?userId="+list[i].userId+"' target='_blank'>"+list[i].userNickName+"</a></dd><dd class='connection_pos'>"+list[i].userBrief+"</dd></dl></li>";
						}else{
							msg+="<li><dl><dt><a href='<%=basePath%>learning/personal.jsp?userId="+list[i].userId+"' target='_blank'><img src='<%=basePath %>userIcons/"+list[i].userIcon+"' username='"+list[i].userId+"'></a></dt><dd class='connection_name'><a href='<%=basePath%>learning/personal.jsp?userId="+list[i].userId+"' target='_blank'>"+list[i].userNickName+"</a></dd><dd class='connection_pos'>"+list[i].userBrief+"</dd></dl><div class='letter-btn-con'><a onclick='cancelFocus(this,"+list[i].userId+");return false;' href='#'>取消关注</a></div></li>";
						}
						$("#myConnect").append(msg);
					}
					$("#btnMyFocus").removeClass("current_foucus");
					$("#btnFocusMe").removeClass("current_foucus");
					$("#btnRelation").removeClass("current_foucus");
					$(e).addClass("current_foucus");
					$("#show").attr("onclick","showMore("+type+","+(currentPage+1)+");return false;");
					$("#c_more").show();
					$("#type").val(type);
				});
				
			}
			function showMore(type,currentPage){
				$.post("<%=basePath%>GetAttentionServlet",{attention:$("#attention").val(),type:type,userId:$.cookie("userId"),currentPage:currentPage},function(data,status){
					var json=eval("("+data+")");
					var currentPage=json.currentPage;
					var list=json.list;
					if(list.length==0){
						$("#c_more").hide();
						return;
					}
					for(var i=0;i<list.length;i++){
						var msg=""; 
						if(type=="1"){
							msg+="<li style='height:82px;'><dl><dt><a href='<%=basePath%>learning/personal.jsp?userId="+list[i].userId+"' target='_blank'><img src='<%=basePath %>userIcons/"+list[i].userIcon+"' username='"+list[i].userId+"'></a></dt><dd class='connection_name'><a href='<%=basePath%>learning/personal.jsp?userId="+list[i].userId+"' target='_blank'>"+list[i].userNickName+"</a></dd><dd class='connection_pos'>"+list[i].userBrief+"</dd></dl></li>";
						}else{
							msg+="<li><dl><dt><a href='<%=basePath%>learning/personal.jsp?userId="+list[i].userId+"' target='_blank'><img src='<%=basePath %>userIcons/"+list[i].userIcon+"' username='"+list[i].userId+"'></a></dt><dd class='connection_name'><a href='<%=basePath%>learning/personal.jsp?userId="+list[i].userId+"' target='_blank'>"+list[i].userNickName+"</a></dd><dd class='connection_pos'>"+list[i].userBrief+"</dd></dl><div class='letter-btn-con'><a onclick='cancelFocus(this,"+list[i].userId+");return false;' href='#'>取消关注</a></div></li>";
						}
						$("#myConnect").append(msg);
					}
					$("#show").attr("onclick","showMore("+type+","+(currentPage+1)+");return false;");
				});
				
			}
			
			function cancelFocus(e,userId){
				$.post("<%=basePath%>CancelFocusServlet",{userId:$.cookie("userId"),c_userId:userId,type:$("#type").val()},function(data,status){
					if(data){
						var json=eval("("+data+")");
						$("#btnMyFocus").text("我关注的("+json.myAttention+")");
						$("#btnFocusMe").text("关注我的("+json.attentionMe+")");
						$("#btnRelation").text("相互关注("+json.attentionEachOther+")");
						$(e).text("加关注");
						$(e).attr("onclick","addFocus(this,"+userId+");return false;");
					}else{
						alert("取消失败");
					}
					
				});
			}
			
			function addFocus(e,userId){
				$.post("<%=basePath%>AddFocusServlet",{userId:$.cookie("userId"),a_userId:userId,type:$("#type").val()},function(data,status){
					if(data){
						var json=eval("("+data+")");
						$("#btnMyFocus").text("我关注的("+json.myAttention+")");
						$("#btnFocusMe").text("关注我的("+json.attentionMe+")");
						$("#btnRelation").text("相互关注("+json.attentionEachOther+")");
						$(e).text("取消关注");
						$(e).attr("onclick","cancelFocus(this,"+userId+");return false;");
					}else{
						alert("添加失败");
					}
					
				});
			}
		</script>
		<div class="main clearfix">
    <div class="persion_section">
			<div class="aboutMe">
				<div nodetype="myConnection" nodeindex="my2" data-modal="tab-layer"
					class="myConnection current_content">
					<div class="connection_title_con">
						<ul>
							<li id="btnMyFocus" class="current_foucus" onclick="change_tab(this,0)">我关注的(<%=myAttention %>)</li>
							<li class="interval_line"></li>
							<li id="btnFocusMe" onclick="change_tab(this,1)">关注我的(<%=attentionMe%>)</li>
							<li class="interval_line"></li>
							<li id="btnRelation" onclick="change_tab(this,2)">相互关注(<%=attentionEachOther%>)</li>
						</ul>
					</div>
					<!-- 
					<li class="icon-th-list no-mess" style="margin-bottom: 0; height: auto;"><span>暂时还没有关注关系</span></li>
					 -->
					<div class="connection_list_con clearfix">
						<ul id="myConnect" class="my_connections clearfix">
						<% 
							if(myAttention==0){
						%>
						<li flag="flag" class="icon-th-list no-mess" style="margin-bottom: 0; height: auto;"><span>暂时还没有关注关系</span></li>
						<%  
						} 
						%>
						
						<c:forEach items="${requestScope.list}" var="user">
							<li><dl>
									<dt>
										<a href="<%=basePath%>learning/personal.jsp?userId=${user.userId}" target="_blank"><img
											src="<%=basePath %>userIcons/${user.userIcon}" username="${user.userId}"></a>
									</dt>
									<dd class="connection_name">
										<a href="<%=basePath%>learning/personal.jsp?userId=${user.userId}" target="_blank">${user.userNickName}</a>
									</dd>
									<dd class="connection_pos">${user.userBrief}</dd>
								</dl>
								<div class="letter-btn-con">
									<a
										onclick="cancelFocus(this,'${user.userId}');return false;"
										href="#">
										取消关注</a>
								</div>
								</li>
						</c:forEach>
						</ul>
						<div id="c_more" class="more" style="display: block;">
							<span class="icon-angle-down"></span><a id="show" onclick="showMore(0,2);return false;" href='#'>显示更多</a>
						</div>
					</div>
				</div>
			</div>
		</div>
		</div>
  </body>
</html>
